package com.ruoyi.bus.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.ruoyi.bus.service.NoGenerateServlce;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bus.domain.DissentInfo;
import com.ruoyi.bus.service.IDissentInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 异议信息Controller
 *
 * @author ruoyi
 * @date 2020-04-09
 */
@Controller
@RequestMapping("/bus/dissentInfo")
public class DissentInfoController extends BaseController {
    private String prefix = "bus/dissentInfo";

    @Autowired
    private IDissentInfoService dissentInfoService;

    @Autowired
    private NoGenerateServlce noGenerateServlce;

    @RequiresPermissions("bus:dissentInfo:view")
    @GetMapping()
    public String dissentInfo() {
        return prefix + "/dissentInfo";
    }

    /**
     * 查询异议信息列表
     */
    @RequiresPermissions("bus:dissentInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DissentInfo dissentInfo) {
        startPage();
        return getDataTable(dissentInfoService.list(new QueryWrapper<>(dissentInfo)));
    }

    /**
     * 导出异议信息列表
     */
    @RequiresPermissions("bus:dissentInfo:export")
    @Log(title = "异议信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DissentInfo dissentInfo) {
        List<DissentInfo> list = dissentInfoService.list(new QueryWrapper<>(dissentInfo));
        ExcelUtil<DissentInfo> util = new ExcelUtil<>(DissentInfo.class);
        return util.exportExcel(list, "dissentInfo");
    }

    /**
     * 新增异议信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        DissentInfo dissentInfo = new DissentInfo();
        dissentInfo.setDissentId(noGenerateServlce.getSeqNo("DI", 5));
        mmap.put("dissentInfo", dissentInfo);
        return prefix + "/edit";
    }

    /**
     * 新增保存异议信息
     */
    @RequiresPermissions("bus:dissentInfo:add")
    @Log(title = "异议信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DissentInfo dissentInfo) {

        return toAjax(dissentInfoService.save(dissentInfo));
    }

    /**
     * 修改异议信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        DissentInfo dissentInfo = dissentInfoService.getById(id);
        mmap.put("dissentInfo", dissentInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存异议信息
     */
    @RequiresPermissions("bus:dissentInfo:edit")
    @Log(title = "异议信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DissentInfo dissentInfo) {
        return toAjax(dissentInfoService.updateById(dissentInfo));
    }

    /**
     * 删除异议信息
     */
    @RequiresPermissions("bus:dissentInfo:remove")
    @Log(title = "异议信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dissentInfoService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
    }

    @PostMapping("/sumbit")
    @ResponseBody
    public AjaxResult sumbit(DissentInfo dissentInfo){
        dissentInfo.setDissentStatus("20");
        return toAjax(dissentInfoService.updateById(dissentInfo));

    }
}
